/*
 * This file Copyright (c) 2015. Walle.
 * (http://www.wallellen.com). All rights reserved.
 *
 *
 * This file is dual-licensed under both the
 * Walle Agreement (WA) and the GNU General Public License.
 * You may elect to use one or the other of these licenses.
 *
 * This file is distributed in the hope that it will be
 * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
 * Redistribution, except as permitted by whichever of the GPL
 * or WA you select, is prohibited.
 *
 * 1. For the GPL license (GPL), you can redistribute and/or
 * modify this file under the terms of the GNU General
 * Public License, Version 3, as published by the Free Software
 * Foundation.  You should have received a copy of the GNU
 * General Public License, Version 3 along with this program;
 * if not, write to the Free Software Foundation, Inc., 51
 * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * 2. For the Walle Agreement (WA), this file
 * and the accompanying materials are made available under the
 * terms of the WA which accompanies this distribution, and
 * is available at http://www.wallellen.com/agreement.html
 *
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
 */

package com.wallellen.quartz.server;

import com.wallellen.core.auth.domain.LoginUser;
import com.wallellen.core.sql.query.DataQuery;
import com.wallellen.quartz.domain.QzScheduler;
import com.wallellen.quartz.domain.QzTask;
import com.wallellen.quartz.domain.QzTrigger;
import org.quartz.SchedulerException;

import java.text.ParseException;

/**
 * 计划任务管理
 */
public interface QzSchedulerManagerInter {
    /**
     * 新增实体
     *
     * @param entity
     */
    public QzScheduler insertSchedulerEntity(QzScheduler entity,
                                             LoginUser user);

    /**
     * 启动一个任务
     *
     * @param SchedulerId
     * @throws ClassNotFoundException 类class无法解析
     * @throws ParseException         计划字符串脚本无法解析
     * @throws SchedulerException
     */
    public void startTask(String SchedulerId) throws ClassNotFoundException,
            ParseException, SchedulerException;

    /**
     * 停止一个任务
     *
     * @param SchedulerId
     * @throws SchedulerException
     */
    public void stopTask(String SchedulerId) throws SchedulerException;

    /**
     * 启动调度引擎
     *
     * @throws ParseException
     * @throws ClassNotFoundException
     */
    public void start() throws SchedulerException, ParseException,
            ClassNotFoundException;

    /**
     * 修改实体
     *
     * @param entity
     */
    public QzScheduler editSchedulerEntity(QzScheduler entity,
                                           LoginUser user);

    /**
     * 删除实体
     *
     * @param entity
     */
    public void deleteSchedulerEntity(String entity, LoginUser user);

    /**
     * 获得实体
     *
     * @param id
     * @return
     */
    public QzScheduler getSchedulerEntity(String id);

    /**
     * 创建一个基本查询用来查询当前实体
     *
     * @param query 传入的查询条件封装
     * @return
     */
    public DataQuery createSchedulerSimpleQuery(DataQuery query);

    /**
     * 判断一个任务计划是否启动
     *
     * @param SchedulerId
     * @return
     * @throws SchedulerException
     */
    public boolean isRunningFindScheduler(String SchedulerId)
            throws SchedulerException;

    /**
     * 新增触发器定义实体
     *
     * @param entity
     */
    public QzTrigger insertTriggerEntity(QzTrigger entity,
                                         LoginUser user);

    /**
     * 修改触发器定义实体
     *
     * @param entity
     */
    public QzTrigger editTriggerEntity(QzTrigger entity, LoginUser user);

    /**
     * 删除触发器定义实体
     *
     * @param entity
     */
    public void deleteTriggerEntity(String entity, LoginUser user);

    /**
     * 获得触发器定义实体
     *
     * @param id
     * @return
     */
    public QzTrigger getTriggerEntity(String id);

    /**
     * 创建一个基本查询用来查询当前触发器定义实体
     *
     * @param query 传入的查询条件封装
     * @return
     */
    public DataQuery createTriggerSimpleQuery(DataQuery query);

    /**
     * 新增任务定义实体
     *
     * @param entity
     */
    public QzTask insertTaskEntity(QzTask entity, LoginUser user);

    /**
     * 修改任务定义实体
     *
     * @param entity
     */
    public QzTask editTaskEntity(QzTask entity, LoginUser user);

    /**
     * 删除任务定义实体
     *
     * @param entity
     */
    public void deleteTaskEntity(String entity, LoginUser user);

    /**
     * 获得任务定义实体
     *
     * @param id
     * @return
     */
    public QzTask getTaskEntity(String id);

    /**
     * 创建一个基本查询用来查询当前任务定义实体
     *
     * @param query 传入的查询条件封装
     * @return
     */
    public DataQuery createTaskSimpleQuery(DataQuery query);

    /**
     * 由一个实例获得任务对象
     *
     * @param schedulerId
     * @return
     */
    public QzTask getTaskBySchedulerId(String schedulerId);
}